//
//  MHMainTabBarController.swift
//  MHSinaWeiBo
//
//  Created by a on 15/9/29.
//  Copyright © 2015年 icast. All rights reserved.
//

import UIKit


class MHMainTabBarController: UITabBarController {

    
    @IBOutlet weak var mainTabBar: MHTabBar!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //根据sb加载控制器，设置给UITabBarController 的自控制器
       addChildVC()
        
        //设置composeBtn的监听事件
        mainTabBar.composeBtn.addTarget(self, action: "composeBtnClick", forControlEvents: UIControlEvents.TouchUpInside)
    }
    
    //实现监听方法
    func composeBtnClick() {
        //加载控制器
        let sb = UIStoryboard(name: "MHCompose", bundle: nil)
        //取出来默认是UIViewController ，这里将其转成nav
        let vc = sb.instantiateInitialViewController() as! UINavigationController
        //跳转控制器
        presentViewController(vc, animated: true, completion: nil)
    }
    
    func addChildVC() {
        //设置tabbar的主题颜色
        self.tabBar.tintColor = UIColor.orangeColor()
        
        addChildViewController(stroyboardName: "MHHome", imageName: "tabbar_home", title: "首页")
        
        addChildViewController(stroyboardName: "MHMessage", imageName: "tabbar_message_center", title: "消息")
        
        addChildViewController(stroyboardName: "MHDiscovery", imageName: "tabbar_discover", title: "发现")
        
        addChildViewController(stroyboardName: "MHPreFile", imageName: "tabbar_profile", title: "我")
        
        
    }
    
    func addChildViewController( stroyboardName name: String,imageName :String ,title :String){
        
        //根据名字获取控制器
        let sb = UIStoryboard(name: name, bundle: nil)
        
        let preFileNav = sb.instantiateInitialViewController() as? UINavigationController
        
        //设置title
        preFileNav?.topViewController?.title = title
        
        preFileNav?.tabBarItem.image = UIImage(named: imageName)
        preFileNav?.tabBarItem.selectedImage = UIImage(named: imageName + "highlighted")
        
        self.addChildViewController(preFileNav!)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    


}
